home *** CD-ROM | disk | FTP | other *** search
- Path: rcp6.elan.af.mil!rscernix!danpop
- From: danpop@mail.cern.ch (Dan Pop)
- Newsgroups: comp.lang.c
- Subject: Re: problem w/ realloc
- Date: 21 Mar 96 20:06:03 GMT
- Organization: CERN European Lab for Particle Physics
- Distribution: usa
- Message-ID: <danpop.827438763@rscernix>
- References: <4iqef0$dqq@montana.avicom.net>
- NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
-
- In <4iqef0$dqq@montana.avicom.net> zoot@montana.avicom.net (John Greenup) writes:
-
- >I've been porting a piece of code from AIX 3.2.5 to linux 1.2.8
- >(gcc 2.7.0) recently, and finaly chased down the last :-) bug. The code
- >assumes that if you have a memory block, and you realloc it smaller, it
- >doesn't move the block of memory, it just makes the "usable size" of it
- >smaller.
-
- Such an assumption is silly. It has nothing to do with the C language
- definition, which actually says:
-
- Description
-
- The realloc function changes the size of the object pointed to by
- ptr to the size specified by size . The contents of the object shall
- be unchanged up to the lesser of the new and old sizes. If the new
- size is larger, the value of the newly allocated portion of the object
- is indeterminate. If ptr is a null pointer, the realloc function
- behaves like the malloc function for the specified size. Otherwise,
- if ptr does not match a pointer earlier returned by the calloc ,
- malloc , or realloc function, or if the space has been deallocated by
- a call to the free or realloc function, the behavior is undefined. If
- the space cannot be allocated, the object pointed to by ptr is
- unchanged. If size is zero and ptr is not a null pointer, the object
- it points to is freed.
-
- Returns
-
- The realloc function returns either a null pointer or a pointer to
- the possibly moved allocated space.
-
- There is no mention that the allocated space can be moved only if the
- size is increased.
-
- >revealed that the realloc is moving my pointer! am I mistaken about the
- >standards, or is this a special case I'm not aware of?
-
- You're definitely mistaken about the C language standard.
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-